import abc


class RestUpdate(object):
  def __init__(self,
               req_timestamp,
               res_timestamp,
               msg,
               status=None,
               native_msg=None,
               native_header=None):
    self.req_timestamp = req_timestamp
    self.res_timestamp = res_timestamp
    self.status = status
    self.msg = msg
    self.native_msg = native_msg if native_msg is not None else msg
    self.native_header = native_header

  def response_time(self):
    return self.res_timestamp - self.req_timestamp

  def __str__(self):
    if id(self.msg) == id(self.native_msg):
      return "<RestUpdate %s %s %s %s>" % (self.req_timestamp, self.res_timestamp, self.msg, "==")
    else:
      return "<RestUpdate %s %s %s %s>" % (
          self.req_timestamp, self.res_timestamp, self.msg, self.native_msg)

  def as_json(self):
    return dict(req_timestamp=self.req_timestamp, res_timestamp=self.res_timestamp, msg=self.msg)
  
  def json(self):
    return self.as_json()

  @staticmethod
  def from_json(update_json):
    return RestUpdate(req_timestamp=update_json["req_timestamp"],
                      res_timestamp=update_json["res_timestamp"],
                      status=update_json["status"],
                      msg=update_json["msg"],
                      native_msg=update_json["native_msg"])


class RestClientBase(metaclass=abc.ABCMeta):
  pass
